package com.xin2.dao;

import com.xin2.bean.Customer;

import java.sql.Connection;
import java.sql.Date;
import java.util.List;

public class CustomerDAOimpl extends BaseDao implements CustomerDAO{
    @Override
    public void insert(Connection conn, Customer cust) {
        String sql="insert into customer(cu_id,cu_name,cu_email,cu_birth)values(?,?,?,?)";
        update(conn,sql,cust.getCu_id(),cust.getCu_name(),cust.getCu_email(),cust.getCu_birth());
    }

    @Override
    public void deleteByid(Connection conn, int id) {
        String sql="delete from customer where cu_id=?";
        update(conn,sql,id);
    }

    @Override
    public void update(Connection conn, Customer cust) {
        String sql="update customer set cu_id=?,cu_name=?,cu_email=?,cu_birth=? where cu_id=?";
        update(conn,sql,cust.getCu_id(),cust.getCu_name(),cust.getCu_email(),cust.getCu_birth(),cust.getCu_id());
    }

    @Override
    public Customer getCustmerByid(Connection conn, int id) {

        String sql="select * from customer where cu_id=?";
        Customer customer = getInstance(conn, Customer.class, sql, id);
        return  customer;
    }

    @Override
    public List<Customer> getAll(Connection conn) {
        String sql="select * from customer";
        List<Customer> list = getForlist(conn,Customer.class,sql);
        return list;
    }

    @Override
    public Long getCount(Connection conn) {
        String sql="select count(*) from customer";
        return getValue(conn,sql);
    }

    @Override
    public Date getMaxbirth(Connection conn) {
        String sql="select max(cu_birth) from customer";
        return getMaxbirth(conn);
    }
}
